﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TKToXML.Models;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;

namespace TKToXML.Persistence.ClassMaps
{
    public class HoaDonMap : ClassMapping<HoaDon>
    {
        public HoaDonMap()
        {
            Table("EDHOADON");       
            Id(x => x.Id, map => { map.Column("So_TC"); map.Generator(Generators.GuidComb);});
            Property(x => x.LoaiChungTu, map => map.Column("Loai_CT"));
            Property(x => x.NamChungTu, map => map.Column("Nam_CT"));
            Property(x => x.SoChungTu, map => map.Column("So_CT"));
            Property(x => x.NgayChungTu, map => map.Column("Ngay_CT"));
            Property(x => x.NamTK, map => map.Column("Nam_TK"));
            Property(x => x.SoTK, map => map.Column("So_TK"));            
            Property(x => x.SoHoaDon, map => map.Column("So_HD"));
            Property(x => x.NgayHoaDon, map => map.Column("Ngay_HD"));                                           
            Property(x => x.MaDV, map => map.Column("Ma_DV"));
            Property(x => x.TenDV, map => map.Column("Ten_DV"));
            Property(x => x.MaDVMuaHang, map => map.Column("Ma_DV_MH"));
            Property(x => x.TenDVMuaHang, map => map.Column("Ten_DV_MH"));
            Property(x => x.MaDVBanHang, map => map.Column("Ma_DV_BH"));
            Property(x => x.TenDVBanHang, map => map.Column("Ten_DV_BH"));
            Property(x => x.MaPTTT, map => map.Column("Ma_PTTT"));
            Property(x => x.MaDKGH, map => map.Column("Ma_DK_GH"));
            Property(x => x.MaNguyenTe, map => map.Column("Ma_NT"));
            Property(x => x.TriGiaNguyenTe, map => map.Column("TriGia_NT"));
            Property(x => x.NgayNhapMay, map => map.Column("Ngay_NM"));
            Property(x => x.NguoiNhapMay, map => map.Column("Nguoi_NM"));

            Bag(x => x.HoaDonChiTiets, map =>
            {
                map.Table("EDHOADONCT");
                map.Key(m => m.Column("HoaDonId"));
                map.Cascade(Cascade.All);
                map.Inverse(true);
            },
                x => x.OneToMany(map => map.Class(typeof(HoaDonChiTiet))));
        }
    }
}
